<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<link
	href="/statics/backend/js/kindeditor-4.1.10/themes/default/default.css"
	type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"
	src="/statics/backend/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8"
	src="/statics/backend/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
	 <style>
  .demo-input{padding-left: 10px; height: 38px; min-width: 262px; line-height: 38px; border: 1px solid #e6e6e6;  background-color: #fff;  border-radius: 2px;}
  </style>
<div style="padding:10px 10px 10px 10px">
	<form id="itemAddForm" class="itemForm" method="post">
		<table cellpadding="5">
			<tr>
				<td>出发地:</td>
				<td><a href="javascript:void(0)"
					class="easyui-linkbutton selectFromSta">选择出发地</a> <input
					type="hidden" name="fromSta" style="width: 280px;"></input></td>
			</tr>
			<tr>
				<td>景点:</td>
				<td><a href="javascript:void(0)"
					class="easyui-linkbutton selectItemCat">选择景点</a> <input
					type="hidden" name="scenicId" style="width: 280px;"></input></td>
			</tr>
			<tr>
				<td>旅游标题:</td>
				<td><input class="easyui-textbox" type="text" name="title"
					data-options="required:true" style="width: 280px;"></input></td>
			</tr>
			<tr>
				<td>时间范围:</td>
				<td><input class="demo-input" type="text" name="dateRange"
					placeholder="请选择日期" id="dateRange"
					style="width: 280px;"></input></td>
			</tr>
			<tr>
				<td>项目卖点:</td>
				<td><input class="easyui-textbox" name="sellPoint"
					data-options="multiline:true,validType:'length[0,150]'"
					style="height:60px;width: 280px;"></input></td>
			</tr>
			<tr>
				<td>价格:</td>
				<td><input class="easyui-numberbox" type="text"
					name="priceView"
					data-options="min:1,max:99999999,precision:2,required:true" /> <input
					type="hidden" name="price" /></td>
			</tr>
			<tr>
				<td>限定人数:</td>
				<td><input class="easyui-numberbox" type="text"
					name="peopleNum"
					data-options="min:1,max:99999999,precision:0,required:true" /></td>
			</tr>
			<tr>
				<td>持续时长:</td>
				<td><input class="easyui-textbox" type="text" name="duration"
					data-options="validType:'length[1,30]'" /></td>
			</tr>
			<tr>
				<td>状态:</td>
				<td><select id="cc" class="easyui-combobox" name="status"
					style="width:200px;">
						<option value="1">正常</option>
						<option value="0">下架</option>
						<option value="2">推荐</option>
				</select> <!-- 				<input class="easyui-textbox" type="text" name="status" -->
					<!-- 					data-options="validType:'length[1,30]'" /> --></td>
			</tr>
			<tr>
				<td>景点图片:</td>
				<td><a href="javascript:void(0)"
					class="easyui-linkbutton picFileUpload">上传图片</a> <input
					type="hidden" name="mainImg" /></td>
			</tr>
			<tr>
				<td>项目描述:</td>
				<td><textarea
						style="width:800px;height:300px; visibility:hidden;" name="trdesc"></textarea>
				</td>
			</tr>
			<tr class="params hide">
				<td>商品规格:</td>
				<td></td>
			</tr>
		</table>
		<!-- 		<input type="hidden" name="itemParams" /> -->
	</form>
	<div style="padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">提交</a> <a href="javascript:void(0)"
			class="easyui-linkbutton" onclick="clearForm()">重置</a>
	</div>
</div>

<script>
lay('#version').html('-v'+ laydate.v);
//日期范围选择
laydate.render({ 
  elem: '#dateRange'
  ,range: '~' //或 range: '~' 来自定义分割字符
});
</script>
<script type="text/javascript">
	var itemAddEditor;
	//页面初始化完毕后执行此方法
	$(function() {
		
		//创建富文本编辑器
		itemAddEditor = E3.createEditor("#itemAddForm [name=trdesc]");
		//初始化类目选择和图片上传器
		E3.init({
			fun : function(node) {
				//根据商品的分类id取商品 的规格模板，生成规格信息。第四天内容。
				//E3.changeItemParam(node, "itemAddForm");
			}
		});
	});
	//提交表单
	function submitForm() {
		//有效性验证
		if (!$('#itemAddForm').form('validate')) {
			$.messager.alert('提示', '表单还未填写完成!');
			return;
		}
		//取商品价格，单位为“分”
		$("#itemAddForm [name=price]").val(eval($("#itemAddForm [name=priceView]").val()) * 100);
		//同步文本框中的商品描述
		itemAddEditor.sync();
		//取商品的规格
		/*
		var paramJson = [];
		$("#itemAddForm .params li").each(function(i,e){
			var trs = $(e).find("tr");
			var group = trs.eq(0).text();
			var ps = [];
			for(var i = 1;i<trs.length;i++){
				var tr = trs.eq(i);
				ps.push({
					"k" : $.trim(tr.find("td").eq(0).find("span").text()),
					"v" : $.trim(tr.find("input").val())
				});
			}
			paramJson.push({
				"group" : group,
				"params": ps
			});
		});
		//把json对象转换成字符串
		paramJson = JSON.stringify(paramJson);
		$("#itemAddForm [name=itemParams]").val(paramJson);
		*/
		//ajax的post方式提交表单
		//$("#itemAddForm").serialize()将表单序列号为key-value形式的字符串
		$.post("/manage/trevalproject/save.do", $("#itemAddForm").serialize(), function(data) {
			if (data.status == 0) {
				$.messager.alert('提示', '新增商品成功!');
			}
		});
	}

	function clearForm() {
		$('#itemAddForm').form('reset');
		itemAddEditor.html('');
	}
</script>
